/**
 * 
 */
package edu.buu.refectory.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.buu.refectory.domain.Food;
import edu.buu.refectory.service.FoodService;
import edu.buu.refectory.utils.CommonUtil;

/**
 * @author Bruce<br>
 * @version 1.0<br>
 * @CreateDate 1 May 2016 <br>
 */
@RequestMapping(value="food")
@Controller
public class FoodController {
	
	@Autowired
	private FoodService foodService;
	
	@ResponseBody
	@RequestMapping(method=RequestMethod.POST)
	public ResponseEntity<?> create(Food food){
		return new ResponseEntity<Food>(foodService.create(food), HttpStatus.CREATED);
	}

	
	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
    public ResponseEntity<?> list(HttpServletRequest request){
        Map<String,Object> map = CommonUtil.getParameterMap(request);
    	return new ResponseEntity<Object>(foodService.getList(map), HttpStatus.OK);
    }
	
	
}
